/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * KartuPengawasanTaksiDialog.java
 *
 * Created on Sep 30, 2011, 3:45:07 PM
 */
package com.x3.dishub.ui;

import com.x3.dishub.dao.IjinOperasiDAO;
import com.x3.dishub.dao.KartuPengawasanTaksiDAO;
import com.x3.dishub.dao.KendaraanDAO;
import com.x3.dishub.dao.WarnaDAO;
import com.x3.dishub.entity.Armada;
import com.x3.dishub.entity.IjinOperasi;
import com.x3.dishub.entity.KartuPengawasanTaksi;
import com.x3.dishub.entity.Kendaraan;
import com.x3.dishub.entity.Warna;
import java.awt.Color;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.sql.DataSource;
import javax.swing.JColorChooser;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.view.JRViewer;

/**
 *
 * @author Hendro Steven
 */
public class KartuPengawasanTaksiDialog extends javax.swing.JDialog {

    private WarnaDAO wDao = (WarnaDAO) MainApps.appContext.getBean("warnaDAO");
    private Warna headerColor;
    private Warna backgroudColor;
    private KartuPengawasanTaksiDAO dao = (KartuPengawasanTaksiDAO) MainApps.appContext.getBean("kartuPengawasanTaksiDAO");
    private List<KartuPengawasanTaksi> list;
    private KartuPengawasanTaksi selected;
    private IjinOperasiDAO iDao = (IjinOperasiDAO) MainApps.appContext.getBean("ijinOperasiDAO");
    //private PerusahaanDAO pDao = (PerusahaanDAO) MainApps.appContext.getBean("perusahaanDAO");
    private IjinOperasi ijinOperasi;
    //private Perusahaan perusahaan;
    private SimpleDateFormat formater = new SimpleDateFormat("dd/MM/yyyy");
    private List<Kendaraan> listKendaraan;
    private KendaraanDAO kDao = (KendaraanDAO) MainApps.appContext.getBean("kendaraanDAO");
    private List<IjinOperasi> listIjinOperasi;
    private List<Armada> listArmada;
    private Armada armada;

    /** Creates new form KartuPengawasanTaksiDialog */
    public KartuPengawasanTaksiDialog(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        //this.getContentPane().setBackground(new java.awt.Color(51, 102, 255));
        loadWarna();
        updateWarna();
        this.setLocationRelativeTo(null);
        reloadAllKartu();
    }

    private void loadWarna() {
        headerColor = wDao.getByNama("KartuPengawasanTaksiDialogHd");
        if (headerColor == null) {
            headerColor = new Warna();
            headerColor.setName("KartuPengawasanTaksiDialogHd");
            headerColor.setRgb(-16777012);
            wDao.insert(headerColor);
            loadWarna();
        }
        backgroudColor = wDao.getByNama("KartuPengawasanTaksiDialogBg");
        if (backgroudColor == null) {
            backgroudColor = new Warna();
            backgroudColor.setName("KartuPengawasanTaksiDialogBg");
            backgroudColor.setRgb(-13408513);
            wDao.insert(backgroudColor);
            loadWarna();
        }
    }

    private void updateWarna() {
        headerPanel.setBackground(new Color(headerColor.getRgb()));
        this.getContentPane().setBackground(new Color(backgroudColor.getRgb()));
    }

    private void reloadAllKartu() {
        try {
            list = dao.getAllKartuPengawasanTaksi();
            bindKartu();
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
    }

    private void bindKartu() {
        try {
            String title[] = {"No.Kartu Pengawasan", "No. Ijin Trayek", "No. Kendaraan", "Masa Berlaku"};
            Object[][] data = new Object[list.size()][4];
            int row = 0;
            for (KartuPengawasanTaksi k : list) {
                data[row][0] = k.getNomor();
                data[row][1] = k.getIjinOperasi().getNomor();
                data[row][2] = k.getArmada().getKendaraan().getNomorPolisi();
                data[row][3] = formater.format(k.getTanggalBerlakuMulai()) + " s/d "
                        + formater.format(k.getTanggalBerlakuSelesai());
                ++row;
            }
            TableModel model = new DefaultTableModel(data, title);
            tblKartu.setModel(model);
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        browseKendaraan = new javax.swing.JDialog();
        jLabel22 = new javax.swing.JLabel();
        txtCariNomorPolisi = new javax.swing.JTextField();
        btnCariKendaraan1 = new javax.swing.JButton();
        jScrollPane6 = new javax.swing.JScrollPane();
        tblBrowseKendaraan = new javax.swing.JTable();
        browseTanggal = new javax.swing.JDialog();
        jLabel9 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        tglCariMulai = new org.jdesktop.swingx.JXDatePicker();
        tglCariSelesai = new org.jdesktop.swingx.JXDatePicker();
        btnCari = new javax.swing.JButton();
        pilihIjinOperasi = new javax.swing.JDialog();
        jPanel6 = new javax.swing.JPanel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        txtNoIjinOperasi = new javax.swing.JTextField();
        btnCariIjin = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        tblIjin = new javax.swing.JTable();
        browseArmada = new javax.swing.JDialog();
        jScrollPane7 = new javax.swing.JScrollPane();
        tblBrowseArmada = new javax.swing.JTable();
        headerPanel = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        tabpane = new javax.swing.JTabbedPane();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblKartu = new javax.swing.JTable();
        btnCariNomor = new javax.swing.JButton();
        btnCariKendaraan = new javax.swing.JButton();
        btnCariTanggal = new javax.swing.JButton();
        btnRefresh = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        txtKendaraanArmada = new javax.swing.JTextField();
        txtIjinOperasi = new javax.swing.JTextField();
        tglKartu = new org.jdesktop.swingx.JXDatePicker();
        txtNomor = new javax.swing.JTextField();
        tglBerlakuMulai = new org.jdesktop.swingx.JXDatePicker();
        jLabel8 = new javax.swing.JLabel();
        tglBerlakuSelesai = new org.jdesktop.swingx.JXDatePicker();
        btnBrowseIjin = new javax.swing.JButton();
        btnBrowseKendaraan = new javax.swing.JButton();
        btnSimpan = new javax.swing.JButton();
        btnBuatBaru = new javax.swing.JButton();
        btnHapus = new javax.swing.JButton();
        btnCetak = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        mnuWarna = new javax.swing.JMenu();
        mnuHeader = new javax.swing.JMenuItem();
        mnuBack = new javax.swing.JMenuItem();
        mnuDefault = new javax.swing.JMenuItem();

        jLabel22.setText("Nomor Polisi :");

        btnCariKendaraan1.setText("Cari");
        btnCariKendaraan1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCariKendaraan1ActionPerformed(evt);
            }
        });

        tblBrowseKendaraan.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tblBrowseKendaraan.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblBrowseKendaraanMouseClicked(evt);
            }
        });
        jScrollPane6.setViewportView(tblBrowseKendaraan);

        javax.swing.GroupLayout browseKendaraanLayout = new javax.swing.GroupLayout(browseKendaraan.getContentPane());
        browseKendaraan.getContentPane().setLayout(browseKendaraanLayout);
        browseKendaraanLayout.setHorizontalGroup(
            browseKendaraanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(browseKendaraanLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(browseKendaraanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane6, javax.swing.GroupLayout.DEFAULT_SIZE, 696, Short.MAX_VALUE)
                    .addGroup(browseKendaraanLayout.createSequentialGroup()
                        .addComponent(jLabel22)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtCariNomorPolisi, javax.swing.GroupLayout.PREFERRED_SIZE, 208, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnCariKendaraan1)))
                .addContainerGap())
        );
        browseKendaraanLayout.setVerticalGroup(
            browseKendaraanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(browseKendaraanLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(browseKendaraanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel22)
                    .addComponent(txtCariNomorPolisi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnCariKendaraan1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane6, javax.swing.GroupLayout.DEFAULT_SIZE, 409, Short.MAX_VALUE)
                .addContainerGap())
        );

        jLabel9.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel9.setForeground(new java.awt.Color(255, 255, 255));
        jLabel9.setText("Pilih Tanggal Masa Berakhir Kartu Pengawasan");

        jLabel12.setForeground(new java.awt.Color(255, 255, 255));
        jLabel12.setText("Mulai Tanggal :");

        jLabel13.setForeground(new java.awt.Color(255, 255, 255));
        jLabel13.setText("Sampai Tanggal :");

        btnCari.setText("Cari");
        btnCari.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCariActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout browseTanggalLayout = new javax.swing.GroupLayout(browseTanggal.getContentPane());
        browseTanggal.getContentPane().setLayout(browseTanggalLayout);
        browseTanggalLayout.setHorizontalGroup(
            browseTanggalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(browseTanggalLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(browseTanggalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(browseTanggalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(browseTanggalLayout.createSequentialGroup()
                            .addGroup(browseTanggalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jLabel12)
                                .addComponent(jLabel13))
                            .addContainerGap(249, Short.MAX_VALUE))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, browseTanggalLayout.createSequentialGroup()
                            .addGroup(browseTanggalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(tglCariSelesai, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 321, Short.MAX_VALUE)
                                .addComponent(tglCariMulai, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 321, Short.MAX_VALUE)
                                .addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addContainerGap()))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, browseTanggalLayout.createSequentialGroup()
                        .addComponent(btnCari)
                        .addContainerGap())))
        );
        browseTanggalLayout.setVerticalGroup(
            browseTanggalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(browseTanggalLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel9)
                .addGap(18, 18, 18)
                .addComponent(jLabel12)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tglCariMulai, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel13)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tglCariSelesai, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 49, Short.MAX_VALUE)
                .addComponent(btnCari)
                .addContainerGap())
        );

        jPanel6.setBackground(new java.awt.Color(0, 0, 204));
        jPanel6.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel10.setFont(new java.awt.Font("Tahoma", 1, 20));
        jLabel10.setForeground(new java.awt.Color(255, 255, 255));
        jLabel10.setText("Daftar Ijin Operasi");

        jLabel11.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel11.setForeground(new java.awt.Color(255, 255, 255));
        jLabel11.setText("Pilih Ijin Operasi untuk Kartu Pengawasan");

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jLabel11))
                    .addComponent(jLabel10))
                .addContainerGap(470, Short.MAX_VALUE))
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel10)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel11)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jLabel14.setText("Nomor :");

        btnCariIjin.setText("Cari");
        btnCariIjin.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCariIjinActionPerformed(evt);
            }
        });

        tblIjin.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tblIjin.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblIjinMouseClicked(evt);
            }
        });
        jScrollPane3.setViewportView(tblIjin);

        javax.swing.GroupLayout pilihIjinOperasiLayout = new javax.swing.GroupLayout(pilihIjinOperasi.getContentPane());
        pilihIjinOperasi.getContentPane().setLayout(pilihIjinOperasiLayout);
        pilihIjinOperasiLayout.setHorizontalGroup(
            pilihIjinOperasiLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(pilihIjinOperasiLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel14)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtNoIjinOperasi, javax.swing.GroupLayout.PREFERRED_SIZE, 288, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnCariIjin)
                .addContainerGap(322, Short.MAX_VALUE))
            .addGroup(pilihIjinOperasiLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 699, Short.MAX_VALUE)
                .addContainerGap())
        );
        pilihIjinOperasiLayout.setVerticalGroup(
            pilihIjinOperasiLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pilihIjinOperasiLayout.createSequentialGroup()
                .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pilihIjinOperasiLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel14)
                    .addComponent(txtNoIjinOperasi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnCariIjin))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        tblBrowseArmada.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tblBrowseArmada.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblBrowseArmadaMouseClicked(evt);
            }
        });
        jScrollPane7.setViewportView(tblBrowseArmada);

        javax.swing.GroupLayout browseArmadaLayout = new javax.swing.GroupLayout(browseArmada.getContentPane());
        browseArmada.getContentPane().setLayout(browseArmadaLayout);
        browseArmadaLayout.setHorizontalGroup(
            browseArmadaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(browseArmadaLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane7, javax.swing.GroupLayout.DEFAULT_SIZE, 696, Short.MAX_VALUE)
                .addContainerGap())
        );
        browseArmadaLayout.setVerticalGroup(
            browseArmadaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(browseArmadaLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane7, javax.swing.GroupLayout.DEFAULT_SIZE, 409, Short.MAX_VALUE)
                .addContainerGap())
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        headerPanel.setBackground(new java.awt.Color(0, 0, 204));
        headerPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 20));
        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
        jLabel1.setText("Kartu Pengawasan Taksi");

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel2.setForeground(new java.awt.Color(255, 255, 255));
        jLabel2.setText("Menambah, mengubah dan menghapus kartu pengawasan taksi");

        javax.swing.GroupLayout headerPanelLayout = new javax.swing.GroupLayout(headerPanel);
        headerPanel.setLayout(headerPanelLayout);
        headerPanelLayout.setHorizontalGroup(
            headerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(headerPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(headerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(headerPanelLayout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jLabel2))
                    .addComponent(jLabel1))
                .addContainerGap(496, Short.MAX_VALUE))
        );
        headerPanelLayout.setVerticalGroup(
            headerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(headerPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel2)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        tblKartu.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tblKartu.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblKartuMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tblKartu);

        btnCariNomor.setText("Cari Berdasarkan Nomor");
        btnCariNomor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCariNomorActionPerformed(evt);
            }
        });

        btnCariKendaraan.setText("Cari Berdasarkan Kendaraan");
        btnCariKendaraan.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCariKendaraanActionPerformed(evt);
            }
        });

        btnCariTanggal.setText("Cari Berdasarkan Tanggal Berlaku");
        btnCariTanggal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCariTanggalActionPerformed(evt);
            }
        });

        btnRefresh.setText("Refresh Tabel");
        btnRefresh.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRefreshActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 823, Short.MAX_VALUE)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(btnCariNomor)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnCariKendaraan)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnCariTanggal)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 201, Short.MAX_VALUE)
                        .addComponent(btnRefresh)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 416, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnCariNomor)
                    .addComponent(btnCariKendaraan)
                    .addComponent(btnCariTanggal)
                    .addComponent(btnRefresh))
                .addContainerGap())
        );

        tabpane.addTab("Daftar Kartu Pengawasan", jPanel2);

        jLabel3.setText("Nomor :");

        jLabel4.setText("Tanggal :");

        jLabel5.setText("Ijin Operasi :");

        jLabel6.setText("Kendaraan/Armada :");

        jLabel7.setText("Masa Berlaku :");

        txtKendaraanArmada.setEditable(false);

        txtIjinOperasi.setEditable(false);

        jLabel8.setText("s/d");

        btnBrowseIjin.setText("....");
        btnBrowseIjin.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBrowseIjinActionPerformed(evt);
            }
        });

        btnBrowseKendaraan.setText("....");
        btnBrowseKendaraan.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBrowseKendaraanActionPerformed(evt);
            }
        });

        btnSimpan.setText("Simpan");
        btnSimpan.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSimpanActionPerformed(evt);
            }
        });

        btnBuatBaru.setText("Buat Baru");
        btnBuatBaru.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBuatBaruActionPerformed(evt);
            }
        });

        btnHapus.setText("Hapus");
        btnHapus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnHapusActionPerformed(evt);
            }
        });

        btnCetak.setText("Cetak Kartu Pengawasan");
        btnCetak.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCetakActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel7, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txtKendaraanArmada, javax.swing.GroupLayout.DEFAULT_SIZE, 206, Short.MAX_VALUE)
                            .addComponent(txtIjinOperasi, javax.swing.GroupLayout.PREFERRED_SIZE, 279, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtNomor)
                            .addComponent(tglKartu, javax.swing.GroupLayout.DEFAULT_SIZE, 183, Short.MAX_VALUE)
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addComponent(tglBerlakuMulai, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel8)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(tglBerlakuSelesai, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(btnBrowseIjin)
                            .addComponent(btnBrowseKendaraan)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                        .addComponent(btnCetak)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 449, Short.MAX_VALUE)
                        .addComponent(btnHapus)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnBuatBaru)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnSimpan)))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txtNomor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(tglKartu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(txtIjinOperasi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnBrowseIjin))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(txtKendaraanArmada, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnBrowseKendaraan))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(tglBerlakuMulai, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8)
                    .addComponent(tglBerlakuSelesai, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 288, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnSimpan)
                    .addComponent(btnBuatBaru)
                    .addComponent(btnHapus)
                    .addComponent(btnCetak))
                .addContainerGap())
        );

        tabpane.addTab("Detail / Buat Baru", jPanel3);

        mnuWarna.setText("Seting");

        mnuHeader.setText("Warna Header");
        mnuHeader.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuHeaderActionPerformed(evt);
            }
        });
        mnuWarna.add(mnuHeader);

        mnuBack.setText("Warna Background");
        mnuBack.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuBackActionPerformed(evt);
            }
        });
        mnuWarna.add(mnuBack);

        mnuDefault.setText("Warna Default");
        mnuDefault.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuDefaultActionPerformed(evt);
            }
        });
        mnuWarna.add(mnuDefault);

        jMenuBar1.add(mnuWarna);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(headerPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addComponent(tabpane, javax.swing.GroupLayout.DEFAULT_SIZE, 848, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(headerPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(tabpane, javax.swing.GroupLayout.DEFAULT_SIZE, 495, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnCariNomorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCariNomorActionPerformed
        try {
            list = dao.getByNomor(JOptionPane.showInputDialog(this, "Nomor :"));
            bindKartu();
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
    }//GEN-LAST:event_btnCariNomorActionPerformed

    private void btnCariKendaraanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCariKendaraanActionPerformed
        try {
            listKendaraan = kDao.getAll();
            String title[] = {"No. Polisi", "No.Uji", "Merk/Type", "Tahun"};
            Object[][] data = new Object[listKendaraan.size()][4];
            int row = 0;
            for (Kendaraan k : listKendaraan) {
                data[row][0] = k.getNomorPolisi();
                data[row][1] = k.getNomorUji();
                data[row][2] = k.getMerk() + k.getType();
                data[row][3] = k.getTahunPembuatan();
                ++row;
            }
            TableModel model = new DefaultTableModel(data, title);
            tblBrowseKendaraan.setModel(model);
            browseKendaraan.setSize(800, 600);
            browseKendaraan.getContentPane().setBackground(new java.awt.Color(51, 102, 255));
            browseKendaraan.setModal(true);
            browseKendaraan.setVisible(true);
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
    }//GEN-LAST:event_btnCariKendaraanActionPerformed

    private void btnCariKendaraan1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCariKendaraan1ActionPerformed
        try {
            listKendaraan = kDao.getByNomorPolisi(txtCariNomorPolisi.getText());
            String title[] = {"No. Polisi", "No.Uji", "Merk/Type", "Tahun"};
            Object[][] data = new Object[listKendaraan.size()][4];
            int row = 0;
            for (Kendaraan k : listKendaraan) {
                data[row][0] = k.getNomorPolisi();
                data[row][1] = k.getNomorUji();
                data[row][2] = k.getMerk() + k.getType();
                data[row][3] = k.getTahunPembuatan();
                ++row;
            }
            TableModel model = new DefaultTableModel(data, title);
            tblBrowseKendaraan.setModel(model);
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
}//GEN-LAST:event_btnCariKendaraan1ActionPerformed

    private void tblBrowseKendaraanMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblBrowseKendaraanMouseClicked
        try {
            Kendaraan kendaraan = (Kendaraan) listKendaraan.get(tblBrowseKendaraan.getSelectedRow());
            list = dao.getByKendaraan(kendaraan);
            bindKartu();
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
        browseKendaraan.setVisible(false);
}//GEN-LAST:event_tblBrowseKendaraanMouseClicked

    private void btnCariTanggalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCariTanggalActionPerformed
        browseTanggal.setLocationRelativeTo(this);
        browseTanggal.getContentPane().setBackground(new java.awt.Color(51, 102, 255));
        browseTanggal.setSize(350, 250);
        browseTanggal.setModal(true);
        browseTanggal.setVisible(true);
    }//GEN-LAST:event_btnCariTanggalActionPerformed

    private void btnCariActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCariActionPerformed
        try {
            list = dao.getByDate(tglCariMulai.getDate(), tglCariSelesai.getDate());
            bindKartu();
            browseTanggal.setVisible(false);
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
}//GEN-LAST:event_btnCariActionPerformed

    private void btnRefreshActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRefreshActionPerformed
        reloadAllKartu();
    }//GEN-LAST:event_btnRefreshActionPerformed

    private void tblKartuMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblKartuMouseClicked
        if (list.size() > 0) {
            selected = list.get(tblKartu.getSelectedRow());
            txtNomor.setText(selected.getNomor());
            tglKartu.setDate(selected.getTanggal());
            txtIjinOperasi.setText(selected.getIjinOperasi().getNomor());
            txtKendaraanArmada.setText(selected.getArmada().getKendaraan().getNomorPolisi());
            tglBerlakuMulai.setDate(selected.getTanggalBerlakuMulai());
            tglBerlakuSelesai.setDate(selected.getTanggalBerlakuSelesai());
            armada = selected.getArmada();
            ijinOperasi = selected.getIjinOperasi();
        }
    }//GEN-LAST:event_tblKartuMouseClicked

    private void btnBrowseIjinActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBrowseIjinActionPerformed
        try {
            listIjinOperasi = iDao.getAllIjinOperasi();
            bindIjinOperasi();
            pilihIjinOperasi.setLocationRelativeTo(null);
            pilihIjinOperasi.getContentPane().setBackground(new java.awt.Color(51, 102, 255));
            pilihIjinOperasi.setSize(600, 500);
            pilihIjinOperasi.setModal(true);
            pilihIjinOperasi.setVisible(true);
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
    }//GEN-LAST:event_btnBrowseIjinActionPerformed

    private void bindIjinOperasi() {
        try {
            String title[] = {"Nomor", "Perusahaan", "Masa Berlaku"};
            Object data[][] = new Object[listIjinOperasi.size()][3];
            int row = 0;
            for (IjinOperasi i : listIjinOperasi) {
                data[row][0] = i.getNomor();
                data[row][1] = i.getPerusahaan().getNama();
                data[row][2] = formater.format(i.getMasaBerlakuMulai()) + " s/d "
                        + formater.format(i.getMasaBerlakuSelesai());
                ++row;
            }
            TableModel model = new DefaultTableModel(data, title);
            tblIjin.setModel(model);
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
    }

    private void btnCariIjinActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCariIjinActionPerformed
        try {
            listIjinOperasi = iDao.getByNomor(txtNoIjinOperasi.getText());
            bindIjinOperasi();
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
}//GEN-LAST:event_btnCariIjinActionPerformed

    private void tblIjinMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblIjinMouseClicked
        ijinOperasi = listIjinOperasi.get(tblIjin.getSelectedRow());
        txtIjinOperasi.setText(ijinOperasi.getNomor());
        pilihIjinOperasi.setVisible(false);
}//GEN-LAST:event_tblIjinMouseClicked

    private void btnBrowseKendaraanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBrowseKendaraanActionPerformed
        try {
            listArmada = ijinOperasi.getArmadas();
            String title[] = {"No. Polisi", "No.Uji", "Merk/Type", "Tahun"};
            Object[][] data = new Object[listArmada.size()][4];
            int row = 0;
            for (Armada a : listArmada) {
                Kendaraan k = a.getKendaraan();
                data[row][0] = k.getNomorPolisi();
                data[row][1] = k.getNomorUji();
                data[row][2] = k.getMerk() + k.getType();
                data[row][3] = k.getTahunPembuatan();
                ++row;
            }
            TableModel model = new DefaultTableModel(data, title);
            tblBrowseArmada.setModel(model);
            browseArmada.setSize(800, 600);
            browseArmada.getContentPane().setBackground(new java.awt.Color(51, 102, 255));
            browseArmada.setModal(true);
            browseArmada.setVisible(true);
        } catch (Exception ex) {
            ex.printStackTrace();
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
    }//GEN-LAST:event_btnBrowseKendaraanActionPerformed

    private void tblBrowseArmadaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblBrowseArmadaMouseClicked
        if (listArmada.size() > 0) {
            armada = listArmada.get(tblBrowseArmada.getSelectedRow());
            txtKendaraanArmada.setText(armada.getKendaraan().getNomorPolisi());
            browseArmada.setVisible(false);
        }
}//GEN-LAST:event_tblBrowseArmadaMouseClicked

    private void btnSimpanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSimpanActionPerformed
        try {
            if (!txtNomor.getText().isEmpty() && ijinOperasi != null & armada != null) {
                if (selected == null) {
                    KartuPengawasanTaksi k = new KartuPengawasanTaksi();
                    k.setNomor(txtNomor.getText());
                    k.setTanggal(tglKartu.getDate());
                    k.setIjinOperasi(ijinOperasi);
                    k.setArmada(armada);
                    k.setTanggalBerlakuMulai(tglBerlakuMulai.getDate());
                    k.setTanggalBerlakuSelesai(tglBerlakuSelesai.getDate());
                    dao.insert(k);
                    armada = null;
                    ijinOperasi = null;
                } else {
                    selected.setNomor(txtNomor.getText());
                    selected.setTanggal(tglKartu.getDate());
                    selected.setIjinOperasi(ijinOperasi);
                    selected.setArmada(armada);
                    selected.setTanggalBerlakuMulai(tglBerlakuMulai.getDate());
                    selected.setTanggalBerlakuSelesai(tglBerlakuSelesai.getDate());
                    dao.update(selected);
                    selected = null;
                    armada = null;
                    ijinOperasi = null;
                }
                reloadAllKartu();
                txtNomor.setText("");
                tglKartu.setDate(new Date());
                txtIjinOperasi.setText("");
                txtKendaraanArmada.setText("");
                tglBerlakuMulai.setDate(new Date());
                tglBerlakuSelesai.setDate(new Date());
                JOptionPane.showMessageDialog(this, "Data tersimpan");
                tabpane.setSelectedIndex(0);
            } else {
                JOptionPane.showMessageDialog(this, "Input data dengan lengkap");
            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
    }//GEN-LAST:event_btnSimpanActionPerformed

    private void btnBuatBaruActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuatBaruActionPerformed
        selected = null;
        txtNomor.setText("");
        tglKartu.setDate(new Date());
        txtIjinOperasi.setText("");
        txtKendaraanArmada.setText("");
        tglBerlakuMulai.setDate(new Date());
        tglBerlakuSelesai.setDate(new Date());
        ijinOperasi = null;
        armada = null;
        txtNomor.requestFocus();
    }//GEN-LAST:event_btnBuatBaruActionPerformed

    private void btnHapusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnHapusActionPerformed
        if (selected != null) {
            dao.delete(selected);
            reloadAllKartu();
            txtNomor.setText("");
            tglKartu.setDate(new Date());
            txtIjinOperasi.setText("");
            txtKendaraanArmada.setText("");
            tglBerlakuMulai.setDate(new Date());
            tglBerlakuSelesai.setDate(new Date());
            armada = null;
            ijinOperasi = null;
            selected = null;
        }
    }//GEN-LAST:event_btnHapusActionPerformed

    private void btnCetakActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCetakActionPerformed

        try {
            if (selected != null) {
                //ambil parameter
                Map mp = new HashMap();
                mp.put("nomor", selected.getNomor());

                DataSource ds = (DataSource) MainApps.appContext.getBean("dataSource");
                JDialog printView = new JDialog();
                JasperPrint print = JasperFillManager.fillReport("print/kartuPengawasanTaksi.jasper",
                        mp, ds.getConnection());
                JRViewer viewer = new JRViewer(print);
                printView.getContentPane().add(viewer);
                printView.setModal(false);
                printView.setTitle("Print Ijin Trayek");
                printView.setSize(800, 500);
                printView.setVisible(true);
            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
}//GEN-LAST:event_btnCetakActionPerformed

    private void mnuHeaderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuHeaderActionPerformed
        Color tmp = JColorChooser.showDialog(this, "Ganti Warna Header", headerPanel.getBackground());
        headerColor.setRgb(tmp.getRGB());
        wDao.update(headerColor);
        updateWarna();
    }//GEN-LAST:event_mnuHeaderActionPerformed

    private void mnuBackActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuBackActionPerformed
        Color tmp = JColorChooser.showDialog(this, "Ganti Warna Backgroud", this.getContentPane().getBackground());
        backgroudColor.setRgb(tmp.getRGB());
        wDao.update(backgroudColor);
        updateWarna();
    }//GEN-LAST:event_mnuBackActionPerformed

    private void mnuDefaultActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuDefaultActionPerformed
        headerColor.setRgb(-16777012);
        backgroudColor.setRgb(-13408513);
        wDao.update(headerColor);
        wDao.update(backgroudColor);
        updateWarna();
    }//GEN-LAST:event_mnuDefaultActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JDialog browseArmada;
    private javax.swing.JDialog browseKendaraan;
    private javax.swing.JDialog browseTanggal;
    private javax.swing.JButton btnBrowseIjin;
    private javax.swing.JButton btnBrowseKendaraan;
    private javax.swing.JButton btnBuatBaru;
    private javax.swing.JButton btnCari;
    private javax.swing.JButton btnCariIjin;
    private javax.swing.JButton btnCariKendaraan;
    private javax.swing.JButton btnCariKendaraan1;
    private javax.swing.JButton btnCariNomor;
    private javax.swing.JButton btnCariTanggal;
    private javax.swing.JButton btnCetak;
    private javax.swing.JButton btnHapus;
    private javax.swing.JButton btnRefresh;
    private javax.swing.JButton btnSimpan;
    private javax.swing.JPanel headerPanel;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JScrollPane jScrollPane7;
    private javax.swing.JMenuItem mnuBack;
    private javax.swing.JMenuItem mnuDefault;
    private javax.swing.JMenuItem mnuHeader;
    private javax.swing.JMenu mnuWarna;
    private javax.swing.JDialog pilihIjinOperasi;
    private javax.swing.JTabbedPane tabpane;
    private javax.swing.JTable tblBrowseArmada;
    private javax.swing.JTable tblBrowseKendaraan;
    private javax.swing.JTable tblIjin;
    private javax.swing.JTable tblKartu;
    private org.jdesktop.swingx.JXDatePicker tglBerlakuMulai;
    private org.jdesktop.swingx.JXDatePicker tglBerlakuSelesai;
    private org.jdesktop.swingx.JXDatePicker tglCariMulai;
    private org.jdesktop.swingx.JXDatePicker tglCariSelesai;
    private org.jdesktop.swingx.JXDatePicker tglKartu;
    private javax.swing.JTextField txtCariNomorPolisi;
    private javax.swing.JTextField txtIjinOperasi;
    private javax.swing.JTextField txtKendaraanArmada;
    private javax.swing.JTextField txtNoIjinOperasi;
    private javax.swing.JTextField txtNomor;
    // End of variables declaration//GEN-END:variables
}
